package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.User;
import com.itheima.service.SystemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/system")
public class SystemController {
    @Reference
    private SystemService systemService;

    @RequestMapping("/login")
    public Result login(@RequestBody Map map, HttpSession session) {
        try {
            User user = systemService.findUsrByNameAndPsw(map);
            session.setAttribute("usr",user);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"账号或密码错误");
        }
        return new Result(true,"登陆成功");
    }


}
